#include "Page.hpp"
#include "ContainerControl.hpp"
#include <map>
#include "Application.hpp"
using namespace NAMESPACENAME;
extern std::map<HWND, Control*> __mapWindows;
Page::Page(const Rectangle& rect, String title, ContainerControl* parent) :
	ContainerControl(rect, parent)
{
	auto p(title.UnsafeGetString());
	hWnd = CreateWindowExW(
		0,
		L"ChildWindow",
		p,
		WS_CHILD | WS_CLIPSIBLINGS,
		rect.x,
		rect.y,
		rect.width,
		rect.height,
		parent->WindowHandle(),
		GetId(parent),
		Application::GetInstance(),
		nullptr
	);
	delete[] p;
	if (hWnd)
		__mapWindows.emplace(std::make_pair(hWnd, this));
	else
		throw std::exception("Create Page Failed!", 0);
}
void Page::OnDestroy()
{
}
void Page::OnClose()
{
}
void Page::OnNcPaint(HRGN hRgn)
{
}
void Page::OnCommand(UINT message, UINT id, Control* control)
{
	parent->OnCommand(message, id, control);
}
void Page::OnLoad()
{
	::ShowWindowAsync(hWnd, SW_NORMAL);
}
void Page::OnUnLoad()
{
	::ShowWindow(hWnd, SW_HIDE);
}
void Page::OnPaint()
{
}